package cn.daniellee.plugin.wl.listener;

import cn.daniellee.plugin.wl.core.LimitCore;
import cn.daniellee.plugin.wl.model.LimitWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerTeleportEvent;

public class PlayerListener implements Listener {

	@EventHandler
	public void onPlayerTeleport(PlayerTeleportEvent e) {
		Player player = e.getPlayer();
		if (player.isOp()) return;
		if (e.getTo() != null) {
			LimitWorld limitWorld = LimitCore.getLimitWorldByName(e.getTo().getWorld().getName());
			if (limitWorld != null) {
				if (LimitCore.checkCantEnter(player, limitWorld)) {
					e.setCancelled(true);
				}
			}
		}
	}

}
